package es.webapp.exiquets.repository;

import java.util.List;

import javax.persistence.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import es.webapp.exiquets.domain.entities.User;

@Repository(value = "usuarioDAO")
public class UsuariosDAOImpl extends BaseDAOeXiquetsImpl<User> implements UsuariosDAO {
	public UsuariosDAOImpl(){
		setClazz(User.class);
	}
	
	
    @Transactional(readOnly = true)
    public User getUsuarioPorMail(String mail){
    	Query q = getCurrentSession().createQuery("from "+ User.class.getName() +" u where mail like :mail", User.class); 
    	q.setParameter("mail", mail);
    	List<User> usuarios = q.getResultList();
    	User u = null;
    	if(usuarios.size() != 0){
    		u = usuarios.get(0);
    	}
        return u;
    }

}
